package com.shanzhu.hospital.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shanzhu.hospital.entity.po.Surgery;
import com.shanzhu.hospital.entity.vo.SurgeryPageVo;
import com.shanzhu.hospital.mapper.SurgeryMapper;
import com.shanzhu.hospital.service.SurgeryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
@Slf4j//自动生成日志记录器
@Service("SurgeryService")
@RequiredArgsConstructor
public class SurgeryServiceImpl extends ServiceImpl<SurgeryMapper, Surgery> implements SurgeryService {
    @Override
    public List<Surgery> findSurgeryBySid(Integer sId) {
        return Collections.emptyList();
    }

    @Override
    public SurgeryPageVo findAllSurgerys(Integer pageNum, Integer pageSize, String query) {
        //分页条件
        Page<Surgery> page = new Page<>(pageNum, pageSize);

        //查询条件
        LambdaQueryWrapper<Surgery> lambdaQuery = Wrappers.<Surgery>lambdaQuery().like(Surgery::getSId, query);

        //分页查询
        IPage<Surgery> iPage = this.page(page, lambdaQuery);

        //组装结果
        SurgeryPageVo pageVo = new SurgeryPageVo();
        pageVo.populatePage(iPage);

        return pageVo;
    }

    @Override
    public Surgery findSurgery(Integer sId) {
        return this.getById(sId);
    }

    @Override
    public Boolean addSurgery(Surgery surgery) {
        //查询床位是否存在
        Surgery exitsurgery = this.getById(surgery.getSId());

        //床位存在，返回false
        if (exitsurgery != null) {
            return Boolean.FALSE;
        }
        //保存床位
        return this.save(surgery);
    }

    @Override
    public Boolean updatesurgery(Surgery surgery) {
        return this.updateById(surgery);
    }

    @Override
    public Boolean deleteSurgery(Integer sId) {
        return this.removeById(sId);
    }
}
